{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 谓词(Predict)\n",
    "\n",
    "原文: https://docs.sympy.org/latest/modules/assumptions/predicates.html\n",
    "\n",
    "## 常见问题(Common)\n",
    "\n",
    "### 同义反复(Tautological)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.common.com monIsTruePredicate(*args, **kwargs)\n",
    "\n",
    "通用谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "`Ask(Q.is_true(x))`是 `true` 当且仅当 `x` 是布尔对象时才有意义。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sympy import ask, Q\n",
    "from sympy.abc import x, y\n",
    "ask(Q.is_true(True))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "包装另一个应用谓词只返回应用谓词。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle Q.even(x)$"
      ],
      "text/plain": [
       "Q.even(x)"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Q.is_true(Q.even(x))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在 SymPy core 中包装二进制关系类返回应用的二进制关系谓词。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle Q.eq(x, y)$"
      ],
      "text/plain": [
       "Q.eq(x, y)"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sympy.core import Eq, Gt\n",
    "Q.is_true(Eq(x, y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle Q.gt(x, y)$"
      ],
      "text/plain": [
       "Q.gt(x, y)"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Q.is_true(Gt(x, y))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 注释\n",
    "\n",
    "这个类被设计用来包装布尔对象，以便它们的行为就像它们是应用谓词一样。因此，包装另一个应用谓词是不必要的，因此它只返回参数。此外，SymPy 核心中的二进制关系类具有表示自身的二进制谓词，因此用 `Q.is_true` 包装它们，将它们转换为这些应用谓词。\n",
    "\n",
    "##### 处理程序\n",
    "\n",
    "多重分派方法: IsTrueHandler\n",
    "\n",
    "允许查询布尔表达式真值的包装器。\n",
    "\n",
    "handler = \\<dispatched IsTrueHandler\\>\n",
    "\n",
    "### 交换性(Commutative)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.common.CommutativePredicate(*args, **kwargs)\n",
    "\n",
    "交换谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "`ask(q.commutative(x))`是真, 当且仅当 x 能够与任何其他对象交换乘法运算。\n",
    "\n",
    "##### 处理程序\n",
    "\n",
    "Multiply dispatched method: CommutativeHandler\n",
    "\n",
    "多重分派方法: 交换处理程序\n",
    "\n",
    "\n",
    "handler = \\<dispatched CommutativeHandler\\>\n",
    "\n",
    "## Calculus 微积分\n",
    "\n",
    "### Finite 有限积分\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.calculus.FinitePredicate(*args, **kwargs)\n",
    "\n",
    "有限数字判定谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "如果 `x` 是一个数，但既不是无穷大，也不是 `NaN`，则 `finite(x)`为真。换句话说，`ask(Q.finite(x))`对于所有具有有界绝对值的数值 `x` 都是正确的。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "False\n",
      "False\n",
      "True\n",
      "True\n",
      "None\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, S, oo, I, zoo\n",
    "from sympy.abc import x\n",
    "print(ask(Q.finite(oo)))\n",
    "print(ask(Q.finite(-oo)))\n",
    "print(ask(Q.finite(zoo)))\n",
    "print(ask(Q.finite(1)))\n",
    "print(ask(Q.finite(2 + 3*I)))\n",
    "print(ask(Q.finite(x), Q.positive(x)))\n",
    "print(ask(Q.finite(S.NaN)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "Multiply dispatched method: FiniteHandler\n",
    "\n",
    "多重分派方法: FiniteHandler\n",
    "\n",
    "处理`Q.finite`. 测试一个表达式对其所有变量都是有界的。\n",
    "\n",
    "##### 参考资料\n",
    "\n",
    "[R5] https://en.wikipedia.org/wiki/Finite\n",
    "\n",
    "handler = \\<dispatched FiniteHandler\\>\n",
    "\n",
    "### Infinite 无限积分\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.calculus.InfinitePredicate(*args, **kwargs)\n",
    "\n",
    "无限数谓词。\n",
    "\n",
    "当 `x` 的绝对值为无穷大时，`Q.infinite (x)`为真。\n",
    "\n",
    "##### 处理程序\n",
    "\n",
    "Multiply dispatched method: InfiniteHandler\n",
    "\n",
    "多重分派方法: InfiniteHandler\n",
    "\n",
    "无限键`Q.infinite`的处理程序。\n",
    "\n",
    "handler = \\<dispatched InfiniteHandler\\>\n",
    "\n",
    "## 矩阵(Matrix)\n",
    "\n",
    "### 对称矩阵(Symmetric)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.matrices.SymmetricPredicate(*args, **kwargs)\n",
    "\n",
    "对称矩阵谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "当且仅当 `x` 是一个方阵且等于它的转置矩阵, `Q.symmetric(x)`为真。每一个方形对角矩阵都是一个对称矩阵。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, MatrixSymbol\n",
    "X = MatrixSymbol('X', 2, 2)\n",
    "Y = MatrixSymbol('Y', 2, 3)\n",
    "Z = MatrixSymbol('Z', 2, 2)\n",
    "print(ask(Q.symmetric(X*Z), Q.symmetric(X) & Q.symmetric(Z)))\n",
    "print(ask(Q.symmetric(X + Z), Q.symmetric(X) & Q.symmetric(Z)))\n",
    "print(ask(Q.symmetric(Y)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: SymmetricHandler\n",
    "\n",
    "Handler for Q.symmetric.\n",
    "\n",
    "对称`Q.symmetric`处理程序。\n",
    "\n",
    "##### 参考资料\n",
    "\n",
    "[R6] https://en.wikipedia.org/wiki/Symmetric_matrix\n",
    "\n",
    "handler = \\<dispatched SymmetricHandler\\>\n",
    "\n",
    "### 可逆矩阵(Invertible)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.matrices.InvertiblePredicate(*args, **kwargs)\n",
    "\n",
    "逆矩阵谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "当且仅当 x 是逆矩阵, `Q.invertible(x)`为真。只有当方阵的行列式`determinant`为0时，方阵才称为可逆矩阵。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, MatrixSymbol\n",
    "X = MatrixSymbol('X', 2, 2)\n",
    "Y = MatrixSymbol('Y', 2, 3)\n",
    "Z = MatrixSymbol('Z', 2, 2)\n",
    "print(ask(Q.invertible(X*Y), Q.invertible(X)))\n",
    "print(ask(Q.invertible(X*Z), Q.invertible(X) & Q.invertible(Z)))\n",
    "print(ask(Q.invertible(X), Q.fullrank(X) & Q.square(X)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: InvertibleHandler\n",
    "\n",
    "可逆 `Q.invertible` 的处理程序。\n",
    "\n",
    "##### 参考资料\n",
    "\n",
    "[R7] https://en.wikipedia.org/wiki/Invertible_matrix\n",
    "\n",
    "handler = \\<dispatched InvertibleHandler\\>\n",
    "\n",
    "### 正交矩阵(Orthogonal)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.matrices.OrthogonalPredicate(*args, **kwargs)\n",
    "\n",
    "正交矩阵谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "当且仅当 `x` 是正交矩阵, `Q.orthogonal(x)`为真。如果方阵 `m` 满足 `M^TM = MM^T = I`，则 `M^T` 是 `M` 的转置矩阵，而 `I` 是单位矩阵，则 `M` 是正交矩阵矩阵。注意，正交矩阵必然是可逆的。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, MatrixSymbol, Identity\n",
    "X = MatrixSymbol('X', 2, 2)\n",
    "Y = MatrixSymbol('Y', 2, 3)\n",
    "Z = MatrixSymbol('Z', 2, 2)\n",
    "print(ask(Q.orthogonal(Y)))\n",
    "print(ask(Q.orthogonal(X*Z*X), Q.orthogonal(X) & Q.orthogonal(Z)))\n",
    "print(ask(Q.orthogonal(Identity(3))))\n",
    "print(ask(Q.invertible(X), Q.orthogonal(X)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: OrthogonalHandler\n",
    "\n",
    "Handler for key ‘orthogonal’.\n",
    "\n",
    "正交`orthogonal`的处理程序。\n",
    "\n",
    "##### 参考资料\n",
    "\n",
    "[R8] https://en.wikipedia.org/wiki/Orthogonal_matrix\n",
    "\n",
    "handler = \\<dispatched OrthogonalHandler\\>\n",
    "\n",
    "### 幺正举证(Unitary)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.matrices.UnitaryPredicate(*args, **kwargs)\n",
    "\n",
    "幺正矩阵谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "`Q.unitary(x)`为真当且仅当 x 是厄米共轭矩阵。厄米共轭矩阵是正交矩阵矩阵的类似物。具有复元素的方阵 `M` 是单一的`unitary`，如果: math: `M^TM = MM^T= I`，其中: math: `M^T` 是 `M` 的共轭转置矩阵。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, MatrixSymbol, Identity\n",
    "X = MatrixSymbol('X', 2, 2)\n",
    "Y = MatrixSymbol('Y', 2, 3)\n",
    "Z = MatrixSymbol('Z', 2, 2)\n",
    "print(ask(Q.unitary(Y)))\n",
    "print(ask(Q.unitary(X*Z*X), Q.unitary(X) & Q.unitary(Z)))\n",
    "print(ask(Q.unitary(Identity(3))))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: UnitaryHandler\n",
    "\n",
    "`unitary`的处理程序。\n",
    "\n",
    "##### 参考资料\n",
    "\n",
    "[R9] https://en.wikipedia.org/wiki/Unitary_matrix\n",
    "\n",
    "handler = \\<dispatched UnitaryHandler\\>\n",
    "\n",
    "### 正定矩阵(Positive Definite)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.matrices.PositiveDefinitePredicate(*args, **kwargs)\n",
    "\n",
    "正定矩阵谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "如果 `M` 是 `math:n \\times n`个对称实矩阵， 则称其为正定的 $𝑍^𝑇𝑀𝑍$ 对于 `n` 个实数的每个非零列向量 `z` 都是正的。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, MatrixSymbol, Identity\n",
    "X = MatrixSymbol('X', 2, 2)\n",
    "Y = MatrixSymbol('Y', 2, 3)\n",
    "Z = MatrixSymbol('Z', 2, 2)\n",
    "print(ask(Q.positive_definite(Y)))\n",
    "print(ask(Q.positive_definite(Identity(3))))\n",
    "print(ask(Q.positive_definite(X + Z), Q.positive_definite(X) & Q.positive_definite(Z)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: PositiveDefiniteHandler\n",
    "\n",
    "正定`positive_definite`处理程序。\n",
    "\n",
    "##### 参考资料\n",
    "\n",
    "[R10] https://en.wikipedia.org/wiki/Positive-definite_matrix\n",
    "\n",
    "handler = \\<dispatched PositiveDefiniteHandler\\>\n",
    "\n",
    "### 上三角矩阵(Upper triangular)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.matrices.UpperTriangularPredicate(*args, **kwargs)\n",
    "\n",
    "上三角矩阵谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "A matrix M is called upper triangular matrix if 𝑀𝑖𝑗=0 for 𝑖<𝑗.\n",
    "\n",
    "矩阵 `M` 称为上三角矩阵，如果 $M_{ij} = 0 for i< j$\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, ZeroMatrix, Identity\n",
    "print(ask(Q.upper_triangular(Identity(3))))\n",
    "print(ask(Q.upper_triangular(ZeroMatrix(3, 3))))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: UpperTriangularHandler\n",
    "\n",
    "上三角形`upper_triangular`的处理程序。\n",
    "\n",
    "##### 参考资料\n",
    "\n",
    "[R11] http://mathworld.wolfram.com/UpperTriangularMatrix.html\n",
    "\n",
    "handler = \\<dispatched UpperTriangularHandler\\>\n",
    "\n",
    "### 下三角矩阵(Lower triangular)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.matrices.LowerTriangularPredicate(*args, **kwargs)\n",
    "\n",
    "下三角矩阵谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "一个矩阵 m 被称为下三角矩阵, 当且仅当 $M_{ij}=0 for i < j$\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, ZeroMatrix, Identity\n",
    "print(ask(Q.lower_triangular(Identity(3))))\n",
    "print(ask(Q.lower_triangular(ZeroMatrix(3, 3))))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: LowerTriangularHandler\n",
    "\n",
    "下三角键`lower_triangular`的处理程序。\n",
    "\n",
    "##### 参考资料\n",
    "\n",
    "[R12] http://mathworld.wolfram.com/LowerTriangularMatrix.html\n",
    "\n",
    "handler = \\<dispatched LowerTriangularHandler\\>\n",
    "\n",
    "### 对角矩阵(Diagonal)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.matrices.DiagonalPredicate(*args, **kwargs)\n",
    "\n",
    "对角矩阵谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "Q.diagonal(x) is true iff x is a diagonal matrix. A diagonal matrix is a matrix in which the entries outside the main diagonal are all zero.\n",
    "\n",
    "`Q.diagonal(x)`为真当且仅当 `x` 是对角矩阵。对角线矩阵是一个矩阵，其中主对角线以外的项都为零。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, MatrixSymbol, ZeroMatrix\n",
    "X = MatrixSymbol('X', 2, 2)\n",
    "print(ask(Q.diagonal(ZeroMatrix(3, 3))))\n",
    "print(ask(Q.diagonal(X), Q.lower_triangular(X) & Q.upper_triangular(X)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: DiagonalHandler\n",
    "\n",
    "Handler for key ‘diagonal’.\n",
    "\n",
    "对角线`diagonal`的处理程序。\n",
    "\n",
    "##### 参考资料\n",
    "\n",
    "[R13] https://en.wikipedia.org/wiki/Diagonal_matrix\n",
    "\n",
    "handler = \\<dispatched DiagonalHandler\\>\n",
    "\n",
    "### 满秩矩阵(Full rank)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.matrices.FullRankPredicate(*args, **kwargs)\n",
    "\n",
    "满秩矩阵谓词。\n",
    "\n",
    "Explanation\n",
    "\n",
    "##### 解释\n",
    "\n",
    "Q.fullrank(x)为真当且仅当 x 是满秩矩阵。如果矩阵的所有行和列都是线性无关的，则该矩阵是满秩的。方阵满秩当且仅当它的行列式是非零的。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, MatrixSymbol, ZeroMatrix, Identity\n",
    "X = MatrixSymbol('X', 2, 2)\n",
    "print(ask(Q.fullrank(X.T), Q.fullrank(X)))\n",
    "print(ask(Q.fullrank(ZeroMatrix(3, 3))))\n",
    "print(ask(Q.fullrank(Identity(3))))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: FullRankHandler\n",
    "\n",
    "Handler for key ‘fullrank’.\n",
    "\n",
    "`fullrank`满秩的处理程序。\n",
    "\n",
    "handler = \\<dispatched FullRankHandler\\>\n",
    "\n",
    "### 方阵(Square)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.matrices.SquarePredicate(*args, **kwargs)\n",
    "\n",
    "方阵谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "`Q.square(x)`为真当且仅当 `x` 是一个方阵。方阵是具有相同行数和列数的矩阵。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, MatrixSymbol, ZeroMatrix, Identity\n",
    "X = MatrixSymbol('X', 2, 2)\n",
    "Y = MatrixSymbol('X', 2, 3)\n",
    "print(ask(Q.square(X)))\n",
    "print(ask(Q.square(Y)))\n",
    "print(ask(Q.square(ZeroMatrix(3, 3))))\n",
    "print(ask(Q.square(Identity(3))))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: SquareHandler\n",
    "\n",
    "`Q.square` 的处理程序。\n",
    "\n",
    "##### 参考资料\n",
    "\n",
    "[R14] https://en.wikipedia.org/wiki/Square_matrix\n",
    "\n",
    "handler = \\<dispatched SquareHandler\\>\n",
    "\n",
    "### 整数矩阵(Integer elements)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.matrices.IntegerElementsPredicate(*args , **kwargs)\n",
    "\n",
    "整数元素矩阵谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "`Q.integer_elements(x)` 为 `true` 当且仅当 `x` 的所有元素都是整数。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, MatrixSymbol\n",
    "X = MatrixSymbol('X', 4, 4)\n",
    "print(ask(Q.integer(X[1, 2]), Q.integer_elements(X)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: IntegerElementsHandler\n",
    "\n",
    "整数矩阵`integer_elements`的处理程序。\n",
    "\n",
    "handler = \\<dispatched IntegerElementsHandler\\>\n",
    "\n",
    "### 实数矩阵(Real elements)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.matrices.RealElementsPredicate(*args, **kwargs)\n",
    "\n",
    "实元素矩阵谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "Q.real_elements(x) is true iff all the elements of x are real numbers.\n",
    "\n",
    "`Q.real_elements(x)`是真的当且仅当 `x` 的所有元素都是实数。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sympy import Q, ask, MatrixSymbol\n",
    "X = MatrixSymbol('X', 4, 4)\n",
    "ask(Q.real(X[1, 2]), Q.real_elements(X))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: RealElementsHandler\n",
    "\n",
    "`real_elements`的处理程序。\n",
    "\n",
    "handler = \\<dispatched RealElementsHandler\\>\n",
    "\n",
    "### 复矩阵(Complex elements)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.matrices.ComplexElementsPredicate(*args, **kwargs)\n",
    "\n",
    "复矩阵谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "当且仅当 `x` 的所有元素都是复数时，`Q.complex_elements(x)`为真。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, MatrixSymbol\n",
    "X = MatrixSymbol('X', 4, 4)\n",
    "print(ask(Q.complex(X[1, 2]), Q.complex_elements(X)))\n",
    "print(ask(Q.complex_elements(X), Q.integer_elements(X)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "复合调度方法: ComplexElementsHandler\n",
    "\n",
    "复杂元素`complex_elements`的处理程序。\n",
    "\n",
    "handler = \\<dispatched ComplexElementsHandler\\>\n",
    "\n",
    "### 奇异矩阵(Singular)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.matrices.SingularPredicate(*args, **kwargs)\n",
    "\n",
    "奇异矩阵谓词。\n",
    "\n",
    "一个矩阵是奇异的当且仅当它的行列式值为0。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, MatrixSymbol\n",
    "X = MatrixSymbol('X', 4, 4)\n",
    "print(ask(Q.singular(X), Q.invertible(X)))\n",
    "print(ask(Q.singular(X), ~Q.invertible(X)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: SingularHandler\n",
    "\n",
    "奇异矩阵谓语。\n",
    "\n",
    "##### 参考资料\n",
    "\n",
    "[R15] http://mathworld.wolfram.com/SingularMatrix.html\n",
    "\n",
    "handler = \\<dispatched SingularHandler\\>\n",
    "\n",
    "### 正规矩阵(Normal)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.matrices.NormalPredicate(*args, **kwargs)\n",
    "\n",
    "正规矩阵谓词。\n",
    "\n",
    "如果一个矩阵与它的共轭与转置是可交换的，那么它是普通矩阵。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sympy import Q, ask, MatrixSymbol\n",
    "X = MatrixSymbol('X', 4, 4)\n",
    "ask(Q.normal(X), Q.unitary(X))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: NormalHandler\n",
    "\n",
    "正规矩阵`normal`谓语的处理程序。\n",
    "\n",
    "##### 参考资料\n",
    "\n",
    "`R16` https://en.wikipedia.org/wiki/Normal_matrix\n",
    "\n",
    "handler = \\<dispatched NormalHandler\\>\n",
    "\n",
    "### 三角矩阵(Triangular)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.matrices.TriangularPredicate(*args, **kwargs)\n",
    "\n",
    "三角矩阵谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "如果 `X` 是下三角形或上三角形，则`Q.triangular(X)`为真。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, MatrixSymbol\n",
    "X = MatrixSymbol('X', 4, 4)\n",
    "print(ask(Q.triangular(X), Q.upper_triangular(X)))\n",
    "print(ask(Q.triangular(X), Q.lower_triangular(X)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: TriangularHandler\n",
    "\n",
    "三角`triangular`断言。\n",
    "\n",
    "##### 参考资料\n",
    "\n",
    "`R17` https://en.wikipedia.org/wiki/Triangular_matrix\n",
    "\n",
    "handler = \\<dispatched TriangularHandler\\>\n",
    "\n",
    "### 单位三角矩阵(Unit triangular)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.matrices.UnitTriangularPredicate(*args, **kwargs)\n",
    "\n",
    "单位三角矩阵谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "一个单位三角矩阵是一个在对角线上有1的三角矩阵。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sympy import Q, ask, MatrixSymbol\n",
    "X = MatrixSymbol('X', 4, 4)\n",
    "ask(Q.triangular(X), Q.unit_triangular(X))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: UnitTriangularHandler\n",
    "\n",
    "`unit_triangular`的处理程序。\n",
    "\n",
    "handler = \\<dispatched UnitTriangularHandler\\>\n",
    "\n",
    "## 数论(Number Theory)\n",
    "\n",
    "### 偶数(Even)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.ntheoryEvenPredicate(*args, **kwargs)\n",
    "\n",
    "偶数谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "`ask(Q.even(x))`是真的当且仅当 `x` 属于偶数集合。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "False\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, pi\n",
    "print(ask(Q.even(0)))\n",
    "print(ask(Q.even(2)))\n",
    "print(ask(Q.even(3)))\n",
    "print(ask(Q.even(pi)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: EvenHandler\n",
    "\n",
    "`even`的处理程序。\n",
    "\n",
    "handler = \\<dispatched EvenHandler\\>\n",
    "\n",
    "### 奇数(Odd)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.ntheoryOddPredicate(*args, **kwargs)\n",
    "\n",
    "奇数谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "`ask(Q.odd(x))`是否为真当且仅当 `x` 属于奇数集。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "False\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, pi\n",
    "print(ask(Q.odd(0)))\n",
    "print(ask(Q.odd(2)))\n",
    "print(ask(Q.odd(3)))\n",
    "print(ask(Q.odd(pi)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: OddHandler\n",
    "\n",
    "`odd`的处理程序, 测试表达式是否表示奇数。\n",
    "\n",
    "handler = \\<dispatched OddHandler\\>\n",
    "\n",
    "### 质数(Prime)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.ntheoryPrimePredicate(*args, **kwargs)\n",
    "\n",
    "素数谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "ask(Q.prime(x)) is true iff x is a natural number greater than 1 that has no positive divisors other than 1 and the number itself.\n",
    "\n",
    "`ask(Q.prime(x))`是否为真当且仅当 `x` 是一个大于1的自然数，除了1和数本身之外没有其他正因子。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "False\n",
      "True\n",
      "False\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask\n",
    "print(ask(Q.prime(0)))\n",
    "print(ask(Q.prime(1)))\n",
    "print(ask(Q.prime(2)))\n",
    "print(ask(Q.prime(20)))\n",
    "print(ask(Q.prime(-3)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: PrimeHandler\n",
    "\n",
    "Handler for key ‘prime’. Test that an expression represents a prime number. When the expression is an exact number, the result (when True) is subject to the limitations of isprime() which is used to return the result.\n",
    "\n",
    "`prime`处理程序。测试表达式是否表示质数。当表达式是一个精确数字时，结果(当为真时)说明用来判定素数的方法 `isprime()`返回真。\n",
    "\n",
    "handler = \\<dispatched PrimeHandler\\>\n",
    "\n",
    "### 合数 Composite\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.ntheoryCompositePredicate(*args, **kwargs)\n",
    "\n",
    "合数谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "`ask(Q.composite(x))`是真的当且仅当 `x` 是一个正整数并且除了1和数字本身以外至少有一个正除数。\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "False\n",
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask\n",
    "print(ask(Q.composite(0)))\n",
    "print(ask(Q.composite(1)))\n",
    "print(ask(Q.composite(2)))\n",
    "print(ask(Q.composite(20)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: CompositeHandler\n",
    "\n",
    "Handler for key ‘composite’.\n",
    "\n",
    "合数关键字`composite`的处理程序。\n",
    "\n",
    "handler = \\<dispatched CompositeHandler\\>\n",
    "\n",
    "## 有序(Order)\n",
    "\n",
    "### 正数(Positive)\n",
    "\n",
    "#### 类 autoclass:: sympy.assumptions.predicates.order.PositivePredicate\n",
    "\n",
    "### 负数(Negative)\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.order.NegativePredicate(*args, **kwargs)\n",
    "\n",
    "负数谓词。\n",
    "\n",
    "##### 解释\n",
    "\n",
    "Q.negative(x) is true iff x is a real number and 𝑥<0, that is, it is in the interval (−∞,0). Note in particular that negative infinity is not negative.\n",
    "\n",
    "`Q.negative(x)`为真当且仅当 `x` 是实数，`x < 0`，即它在区间(- ∞ ，0)(- ∞ ，0)中。特别要注意的是，负无穷并不是负的。\n",
    "\n",
    "关于负数的一些重要事实:\n",
    "\n",
    "Note that Q.nonnegative and ~Q.negative are not the same\n",
    "> - 请注意 `Q.nonnegative 和` `~Q.negative` 是不同的。`~Q.negative(x)`仅表示 `x` 不是负数，而 `Q.nonnegative(x)`表示 `x` 是实数而不是负数，即，`Q.nonnegative(x)`在逻辑上等价于 `Q.zero (x) | Q.positive (x)`。例如，可能存在`~Q.negative(I)`为 `true`，而 `Q.nonnegative(I)`为 `false`。\n",
    "> - 更多信息请参见 `Q.real` 的文档\n",
    "\n",
    "##### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, symbols, I\n",
    "x = symbols('x')\n",
    "print(ask(Q.negative(x), Q.real(x) & ~Q.positive(x) & ~Q.zero(x)))\n",
    "print(ask(Q.negative(-1)))\n",
    "print(ask(Q.nonnegative(I)))\n",
    "print(ask(~Q.negative(I)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 处理程序\n",
    "\n",
    "多重分派方法: NegativeHandler\n",
    "\n",
    "Handler for Q.negative. Test that an expression is strictly less than zero.\n",
    "\n",
    "`Q.negative`的处理程序. 测试表达式是否严格小于零。\n",
    "\n",
    "handler = \\<dispatched NegativeHandler\\>\n",
    "\n",
    "### Zero 零\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.order.ZeroPredicate(*args, **kwargs)\n",
    "\n",
    "零的谓词。\n",
    "\n",
    "#### 解释\n",
    "\n",
    "`ask(Q.zero(x))`是真的当且仅当 `x` 的值为零。\n",
    "\n",
    "#### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "None\n",
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import ask, Q, oo, symbols\n",
    "x, y = symbols('x, y')\n",
    "print(ask(Q.zero(0)))\n",
    "print(ask(Q.zero(1/oo)))\n",
    "print(ask(Q.zero(0*oo)))\n",
    "print(ask(Q.zero(1)))\n",
    "print(ask(Q.zero(x*y), Q.zero(x) | Q.zero(y)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 处理程序\n",
    "\n",
    "多重分派方法: ZeroHandler\n",
    "\n",
    "`zero`的处理程序。\n",
    "\n",
    "handler = \\<dispatched ZeroHandler\\>\n",
    "\n",
    "### 非零 Nonzero \n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.order.NonZeroPredicate(*args, **kwargs)\n",
    "\n",
    "非零实数谓词。\n",
    "\n",
    "#### 解释\n",
    "\n",
    "ask(Q.nonzero(x)) is true iff x is real and x is not zero. Note in particular that Q.nonzero(x) is false if x is not real. Use ~Q.zero(x) if you want the negation of being zero without any real assumptions.\n",
    "\n",
    "`ask(Q.nonzero(x))`是否为真当且仅当 `x` 是实数且 `x` 不为零。特别要注意，如果 `x` 不是实数，那么 `Q.nonzero(x)`是 `false`。如果希望在没有任何实际假设的情况下将否定值设为非零，那么可以使用 `~Q.zero(x)`。\n",
    "\n",
    "关于非零数的一些重要事实:\n",
    "- `Q.nonzero`在逻辑上等价于 `Q.positive | Q.negative`。\n",
    "- 更多信息请参见 `Q.real` 的文档\n",
    "\n",
    "#### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n",
      "True\n",
      "False\n",
      "False\n",
      "False\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, symbols, I, oo\n",
    "x = symbols('x')\n",
    "print(ask(Q.nonzero(x), ~Q.zero(x)))\n",
    "print(ask(Q.nonzero(x), Q.positive(x)))\n",
    "print(ask(Q.nonzero(x), Q.zero(x)))\n",
    "print(ask(Q.nonzero(0)))\n",
    "print(ask(Q.nonzero(I)))\n",
    "print(ask(~Q.zero(I)))\n",
    "print(ask(Q.nonzero(oo)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 处理程序\n",
    "\n",
    "多重分派方法: NonZeroHandler\n",
    "\n",
    "`zero`的处理程序。测试表达式是否为零。\n",
    "\n",
    "handler = \\<dispatched NonZeroHandler\\>\n",
    "\n",
    "### 非正数 Nonpositive \n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.order.NonPositivePredicate(*args, **kwargs)\n",
    "\n",
    "非正实数谓词。\n",
    "\n",
    "#### 解释\n",
    "\n",
    "`ask(Q.nonpositive(x))`是否为真当且仅当 `x` 属于包括零在内的负数集。\n",
    "\n",
    "> 注意 `Q.nonpositive` 和 `~Q.positive` 是不一样的。`~ Q.positive(x)`仅意味着 `x` 不是正的，而 `Q.nonpositive(x)`意味着 `x` 是实数而不是正的，即，`Q.nonpositive(x)`在逻辑上等价于 `Q.negative(x) | Q.zero(x)`。例如，`~ Q.positive(I)`为 `true`，而 `Q.nonpositive(I)`为 `false`。\n",
    "\n",
    "#### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "False\n",
      "False\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, I\n",
    "print(ask(Q.nonpositive(-1)))\n",
    "print(ask(Q.nonpositive(0)))\n",
    "print(ask(Q.nonpositive(1)))\n",
    "print(ask(Q.nonpositive(I)))\n",
    "print(ask(Q.nonpositive(-I)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 处理程序\n",
    "\n",
    "多重分派方法: NonPositiveHandler\n",
    "\n",
    "`nonpositive`的处理程序。\n",
    "\n",
    "handler = \\<dispatched NonPositiveHandler\\>\n",
    "\n",
    "### 非负数 Nonnegative \n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.order.NonNegativePredicate(*args, **kwargs)\n",
    "\n",
    "非负实数谓词。\n",
    "\n",
    "#### 解释\n",
    "\n",
    "`ask(Q.nonnegative(x))`是否为真当且仅当 `x` 属于包含零的正数集合。\n",
    "\n",
    "Note that Q.nonnegative and ~Q.negative are not the same\n",
    "> 请注意 `Q.nonnegative` 和 `~ Q.negative` 是不同的。`~Q.negative(x)`仅表示 `x` 不是负数，而 `Q.nonnegative(x)`表示 `x` 是实数而不是负数，即，`Q.nonnegative (x)`在逻辑上等价于 `Q.zero(x) | Q.positive(x)`。例如，`~Q.negative(i)`为 `true`，而 `Q.nonnegative(i)`为 `false`。\n",
    "\n",
    "#### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "False\n",
      "False\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, I\n",
    "print(ask(Q.nonnegative(1)))\n",
    "print(ask(Q.nonnegative(0)))\n",
    "print(ask(Q.nonnegative(-1)))\n",
    "print(ask(Q.nonnegative(I)))\n",
    "print(ask(Q.nonnegative(-I)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 处理程序\n",
    "\n",
    "多重分派方法: NonNegativeHandler\n",
    "\n",
    "非负数`Q.nonnegative`的处理程序。\n",
    "\n",
    "handler = \\<dispatched NonNegativeHandler\\>\n",
    "\n",
    "## 集合 Sets \n",
    "\n",
    "### 整数 Integer \n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.sets.IntegerPredicate(*args, **kwargs)\n",
    "\n",
    "整数谓词。\n",
    "\n",
    "#### 解释\n",
    "\n",
    "`Q.integer(x)`为 `true` 当且仅当 `x` 属于整数集合。\n",
    "\n",
    "#### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, S\n",
    "print(ask(Q.integer(5)))\n",
    "print(ask(Q.integer(S(1)/2)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 处理程序\n",
    "\n",
    "多重分派方法: IntegerHandler\n",
    "\n",
    "`Q.integer`的处理程序。\n",
    "\n",
    "测试表达式是否属于整数字段。\n",
    "\n",
    "#### 参考资料\n",
    "\n",
    "[R18] https://en.wikipedia.org/wiki/Integer\n",
    "\n",
    "handler = \\<dispatched IntegerHandler\\>\n",
    "\n",
    "### Rational 理性\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.sets.RationalPredicate(*args, **kwargs)\n",
    "\n",
    "有理数谓词。\n",
    "\n",
    "#### 解释\n",
    "\n",
    "`Q.rational(x)`为真当且仅当 `x` 属于有理数集合。\n",
    "\n",
    "#### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "from sympy import ask, Q, pi, S\n",
    "print(ask(Q.rational(0)))\n",
    "print(ask(Q.rational(S(1)/2)))\n",
    "print(ask(Q.rational(pi)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 处理程序\n",
    "\n",
    "多重分派方法: RationalHandler\n",
    "\n",
    "`Q.rational`的处理程序。\n",
    "\n",
    "测试表达式是否属于有理数域。\n",
    "\n",
    "#### 参考资料\n",
    "\n",
    "https://en.wikipedia.org/wiki/Rational_number\n",
    "\n",
    "handler = \\<dispatched RationalHandler\\>\n",
    "\n",
    "### 无理数 Irrational\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.sets.IrrationalPredicate(*args, **kwargs)\n",
    "\n",
    "无理数谓词。\n",
    "\n",
    "#### 解释\n",
    "\n",
    "`Q.irrational(x)`为真当且仅当 `x` 是任何不能用整数比表示的实数。\n",
    "\n",
    "#### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "False\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "from sympy import ask, Q, pi, S, I\n",
    "print(ask(Q.irrational(0)))\n",
    "print(ask(Q.irrational(S(1)/2)))\n",
    "print(ask(Q.irrational(pi)))\n",
    "print(ask(Q.irrational(I)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 处理程序\n",
    "\n",
    "多重分派方法: IrrationalHandler\n",
    "\n",
    "`Q.irrational`的处理程序。\n",
    "\n",
    "测试表达式是否为无理数。\n",
    "\n",
    "#### 参考资料\n",
    "\n",
    "[R19] https://en.wikipedia.org/wiki/Irrational_number\n",
    "\n",
    "handler = \\<dispatched IrrationalHandler\\>\n",
    "\n",
    "### 实数 Real\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.sets.RealPredicate(*args, **kwargs)\n",
    "\n",
    "实数谓词。\n",
    "\n",
    "#### 解释\n",
    "\n",
    "`Q.real(x)`为真当且仅当 `x` 是实数，即它在区间(- ∞ ，∞)中。注意，特别是无穷大是不实数。如果你也想考虑它们，可以使用 `Q.extended_real`。\n",
    "\n",
    "关于实数的一些重要事实:\n",
    "\n",
    "- 每个实数都是正数、负数或零,因为这些集合是不相交的，每个实数都是这三个集合中的一个。\n",
    "- 每个实数也是复数。\n",
    "- 每个实数都是有限数。\n",
    "- 每个实数要么是有理数，要么是无理数。\n",
    "- 每个实数要么是代数的，要么是超越数。\n",
    "- 事实 `Q.negative`， `Q.zero`， `Q.positive`,`Q.nonnegative`, `Q.nonpositive`, `Q.nonzero`, `Q.integer`, `Q.rational`, `Q.irrational` 都是`Q.real`。所有暗示这些事实的事实也是一样的。\n",
    "- 事实`Q.algebraic`, `Q.transcendental` 不意味着`Q.real`; 他们意味着`Q.complex`. 一个代数数或者先验数可能是也可能不是实数.\n",
    "- 非事实 `non` (即 `Q.nonnegative`，`Q.nonzero` 和 `Q.noninteger`)并不等同于他们的反类，而是不等同于反类和 `Q.real`。例如，`Q.nonnegative` 表示 `~ Q.negative & Q.real`。例如，`I` 不是非负的，非零的，也不是非正的。\n",
    "\n",
    "#### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, symbols\n",
    "x = symbols('x')\n",
    "print(ask(Q.real(x), Q.positive(x)))\n",
    "print(ask(Q.real(0)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 处理程序\n",
    "\n",
    "多重分派方法: RealHandler\n",
    "\n",
    "`Q.real`的处理程序。\n",
    "\n",
    "测试表达式是否属于实数。\n",
    "\n",
    "#### 参考资料\n",
    "\n",
    "[R20] https://en.wikipedia.org/wiki/Real_number\n",
    "\n",
    "handler = \\<dispatched RealHandler\\>\n",
    "\n",
    "### 扩展实数 Extended real \n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.sets.ExtendedRealPredicate(*args, **kwargs)\n",
    "\n",
    "扩展实数谓词。\n",
    "\n",
    "#### 解释\n",
    "\n",
    "`Q.extended_real(x)`为真当且仅当 `x` 是实数或{-∞ ，∞}\n",
    "\n",
    "有关相关实数的更多信息，请参见 `Q.real` 的文档。\n",
    "\n",
    "#### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "from sympy import ask, Q, oo, I\n",
    "print(ask(Q.extended_real(1)))\n",
    "print(ask(Q.extended_real(I)))\n",
    "print(ask(Q.extended_real(oo)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 处理程序\n",
    "\n",
    "多重分派方法: ExtendedRealHandler\n",
    "\n",
    "扩展实数`Q.extended_real`的处理程序。\n",
    "\n",
    "测试表达式是否属于扩展实数\n",
    "\n",
    "数字 `numbers`，也就是实数`real`并`{ Infinity,-Infinity }`。\n",
    "\n",
    "handler = \\<dispatched ExtendedRealHandler\\>\n",
    "\n",
    "### 厄米特 Hermitian\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.sets.HermitianPredicate Hermitian(*args, **kwargs)\n",
    "\n",
    "厄尔米特谓词。\n",
    "\n",
    "#### 解释\n",
    "\n",
    "`ask(Q.hermitian(x))`是真的当且仅当 `x` 属于 `Hermitian` 算子集合。\n",
    "\n",
    "#### 处理程序\n",
    "\n",
    "多重分派方法: HermitianHandler\n",
    "\n",
    "`Q.hermitian`的处理程序。\n",
    "\n",
    "检验一个表达式是否属于厄米算符域。\n",
    "\n",
    "#### 参考资料\n",
    "\n",
    "[R21] http://mathworld.wolfram.com/HermitianOperator.html\n",
    "\n",
    "handler = \\<dispatched HermitianHandler\\>\n",
    "\n",
    "### 复数 Complex\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.sets.ComplexPredicate(*args, **kwargs)\n",
    "\n",
    "复数谓词。\n",
    "\n",
    "#### 解释\n",
    "\n",
    "`Q.complex(x)`为真当且仅当 `x` 属于复数集。注意每个复数都是有限的。\n",
    "\n",
    "#### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, Symbol, ask, I, oo\n",
    "x = Symbol('x')\n",
    "print(ask(Q.complex(0)))\n",
    "print(ask(Q.complex(2 + 3*I)))\n",
    "print(ask(Q.complex(oo)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 处理程序\n",
    "\n",
    "多重分派方法: ComplexHandler\n",
    "\n",
    "`Q.complex`的处理程序。\n",
    "\n",
    "测试表达式是否属于复数域。\n",
    "\n",
    "#### 参考资料\n",
    "\n",
    "[R22] https://en.wikipedia.org/wiki/Complex_number\n",
    "\n",
    "handler = \\<dispatched ComplexHandler\\>\n",
    "\n",
    "### 虚数 Imaginary\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.sets.ImaginaryPredicate(*args, **kwargs)\n",
    "\n",
    "虚数谓词。\n",
    "\n",
    "#### 解释\n",
    "\n",
    "`Q.imaginary(x)`是真的当且仅当 `x` 可以被写成实数乘以虚数单位 `I` 时，请注意0不被认为是虚数。\n",
    "\n",
    "#### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "from sympy import Q, ask, I\n",
    "print(ask(Q.imaginary(3*I)))\n",
    "print(ask(Q.imaginary(2 + 3*I)))\n",
    "print(ask(Q.imaginary(0)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 处理程序\n",
    "\n",
    "多重分派方法: ImaginaryHandler\n",
    "\n",
    "`Q.imaginary`的处理程序。\n",
    "\n",
    "测试表达式是否属于虚数域, 也就是形式为 `x * I` 的数，其中 `x` 是实数。\n",
    "\n",
    "#### 参考资料\n",
    "\n",
    "[R23] https://en.wikipedia.org/wiki/Imaginary_number\n",
    "\n",
    "handler = \\<dispatched ImaginaryHandler\\>\n",
    "\n",
    "### 反厄米特 Antihermitian\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.sets.AntihermitianPredicate(*args, **kwargs)\n",
    "\n",
    "反厄米谓词。\n",
    "\n",
    "#### 解释\n",
    "\n",
    "`Q.antihermitian(x)`是真的当且仅当 `x` 属于反厄米特算子域，即形式为 `x * I` 的算子，其中 `x` 是厄米特。\n",
    "\n",
    "#### 处理程序\n",
    "\n",
    "多重分派方法: AntiHermitianHandler\n",
    "\n",
    "`Q.antihermitian` 的处理程序。\n",
    "\n",
    "测试一个表达式属于反厄米特域运算符，也就是 `x * I` 形式的运算符，其中 `x` 是厄米特的。\n",
    "\n",
    "#### 参考资料\n",
    "\n",
    "[R24] http://mathworld.wolfram.com/HermitianOperator.html\n",
    "\n",
    "handler = \\<dispatched AntiHermitianHandler\\>\n",
    "\n",
    "### 代数 Algebraic \n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.sets.AlgebraicPredicate(*args, **kwargs)\n",
    "\n",
    "代数数谓词。\n",
    "\n",
    "#### 解释\n",
    "\n",
    "Q.algebraic(x) is true iff x belongs to the set of algebraic numbers. x is algebraic if there is some polynomial in p(x)\\in \\mathbb\\{Q\\}[x] such that p(x) = 0.\n",
    "\n",
    "`Q.algebraic(x)`是真的当且仅当 `x` 属于代数数集合。如果在 `\\mathbb\\{Q\\}[x]`中则 `x` 是代数的。\n",
    "\n",
    "#### 例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "from sympy import ask, Q, sqrt, I, pi\n",
    "print(ask(Q.algebraic(sqrt(2))))\n",
    "print(ask(Q.algebraic(I)))\n",
    "print(ask(Q.algebraic(pi)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 处理程序\n",
    "\n",
    "多重分派方法: AskAlgebraicpredicateHandler\n",
    "\n",
    "`AskAlgebraicpredicateHandler` 的处理程序\n",
    "\n",
    "#### 参考资料\n",
    "\n",
    "[R25] https://en.wikipedia.org/wiki/Algebraic_number\n",
    "\n",
    "Algebraichandler = \\<dispatched AlgebraicHandler\\>\n",
    "\n",
    "handler = \\<dispatched AskAlgebraicpredicateHandler\\>\n",
    "\n",
    "### 超越数 Transcendental\n",
    "\n",
    "#### 类 class sympy.assumptions.predicates.sets.TranscendentalPredicate(*args, **kwargs)\n",
    "\n",
    "超越数谓词。\n",
    "\n",
    "#### 解释\n",
    "\n",
    "Q.transcendental(x) is true iff x belongs to the set of transcendental numbers. A transcendental number is a real or complex number that is not algebraic.\n",
    "\n",
    "`Q.transcendental(x)`为真当且仅当 `x` 是超越数的集合。超越数是一个非代数的实数或复数。\n",
    "\n",
    "#### 处理程序\n",
    "\n",
    "多重分派方法: Transcendental\n",
    "\n",
    "`Q.transcendental`超越数的处理程序。\n",
    "\n",
    "handler = \\<dispatched Transcendental\\>"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "40d3a090f54c6569ab1632332b64b2c03c39dcf918b08424e98f38b5ae0af88f"
  },
  "kernelspec": {
   "display_name": "Python 3.8.8 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
